package com.museum;

import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import com.museum.data.Mp_Places_Items_Handler;
import com.museum.data.Mp_Places_Museum_Handler;
import com.museum.data.Mp_Places_News_Handler;
import com.museum.data.Mp_User_Bookshelf_Handler;
import com.museum.data.Mp_User_Profile_Handler;
import com.museum.data.Mp_User_Visit_Handler;
import com.museum.data.Mp_User_Watched_Handler;
import com.museum.model.Location;
import com.museum.model.Mp_Places_Items;
import com.museum.model.Mp_Places_Museum;
import com.museum.model.Mp_User_Watched;
import com.museum.model.Open_Date;
import com.museum.model.Open_Date_Item;
import com.museum.model.Place;
import com.museum.model.Visited;
import com.museum.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.support.v4.app.NavUtils;
import android.view.View.OnClickListener;

public class Mp_User_Watched_Activity extends Activity {
	TextView textviewDetail;
	
	private XMLRPCClient client;
	private URI uri;
	Visited visited;
	Place place;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mp_user_watched);
        
        bindWidget();
        setButtonEventListener();
        
        String username = "test";
        String password = "testpwd";
        String result = "";
      //##############Mp_User_Watched##################
        Mp_User_Watched_Handler c = new Mp_User_Watched_Handler(username,password);
        for(int i = 0;i < c.getMp_User_Watched().getPlace_News().getItemCount(); i++){
        	String event_id = c.getMp_User_Watched().getPlace_News().getItem(i).getEvent_id();
        	String display_name = c.getMp_User_Watched().getPlace_News().getItem(i).getDisplay_name();
        	String description = c.getMp_User_Watched().getPlace_News().getItem(i).getDescription();
        	result += "\r\nPlace News:\r\n";
        	result += "\r\n"+ "event_id: " + event_id
	     			 +"\r\n"+ "display_name: "+ display_name
	     			 +"\r\n"+ "description: "+ description;
        	
        	c.getMp_User_Watched().getPlace_News().getItem(i).getPlace_info();
        	 for(int j = 0;j < c.getMp_User_Watched().getPlace_News().getItemCount(); j++){
             	String place_id = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getPlaceId();
               	String name = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getName();
           	    String place_news_description = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getDescription();
           	    String create_timestamp = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getCreate_Timestamp();
           	    String add_timestamp = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getAdded_Timestamp();
           	    String location_description = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getDescription();
           	    String location_latitude = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getLocation().getLatitude();
           	    String location_longitude = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getLocation().getLongitude();
           	    String website = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getWebsite();
           	    String email = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getEmail();
     	      	result += "\r\nplace_id: " + place_id
     	     			 +"\r\n"+ "name: "+ name
     	     			 +"\r\n"+ "description: "+ place_news_description
     	     			 +"\r\n"+ "create_timestamp: "+ create_timestamp
     	     			 +"\r\n"+ "add_timestamp: "+ add_timestamp
     	     			 +"\r\n"+ " location_description: "+ location_description
     	     			 +"\r\n"+ " location_latitude: "+ location_latitude
     	     			 +"\r\n"+ " location_longitude: "+ location_longitude
     	     			 +"\r\n"+ "website: "+ website
     	     			 +"\r\n"+ "email: "+ email;
          			 
           	    for(int k=0;k < c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getOpen_Date().getItemCount();k++){
           	    	String open_date = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getOpen_Date().getItem(k).getDate();
           	    	String open_time = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getOpen_Date().getItem(k).getOpen_time();
           	    	String close_time = c.getMp_User_Watched().getPlace_News().getItem(j).getPlace_info().getOpen_Date().getItem(k).getClose_time();
           	    	
           	    	result += "\r\n"+ " open_date: "+ open_date
     			   			 +"\r\n"+ " open_time: "+ open_time
     			   			 +"\r\n"+ " close_time: "+ close_time;
           	    }
           	    String status = c.getMp_User_Watched().getPlace_News().getItem(i).getPlace_info().getStatus();
           	    String exhibition_status = c.getMp_User_Watched().getPlace_News().getItem(i).getPlace_info().getExhibition_Status();
           	    
           	  result += "\r\n"+ "status: "+ status
     		   			 +"\r\n"+ "exhibition_status: "+ exhibition_status;
             }
        	 
        	String start_date = c.getMp_User_Watched().getPlace_News().getItem(i).getStart_date();
        	String end_date = c.getMp_User_Watched().getPlace_News().getItem(i).getEnd_date();
        	String event_type = c.getMp_User_Watched().getPlace_News().getItem(i).getEvent_type();
        	String flee = c.getMp_User_Watched().getPlace_News().getItem(i).getFlee();
        	String web_site = c.getMp_User_Watched().getPlace_News().getItem(i).getWeb_site();
        	String email = c.getMp_User_Watched().getPlace_News().getItem(i).getEmail();
        	String phone_number = c.getMp_User_Watched().getPlace_News().getItem(i).getPhone_number();
        	result += "\r\n"+ " open_date: "+ start_date
        			+"\r\n"+ "end_date: "+ end_date
		        	+"\r\n"+ "event_type: "+ event_type
		        	+"\r\n"+ "flee: "+ flee
		        	+"\r\n"+ "web_site: "+ web_site
		        	+"\r\n"+ "email: "+ email
		        	+"\r\n"+ "phone_number: "+ phone_number;
        			
        	result += "\r\n##############################";
        	
        	//#############Place######################
        	String place_id = c.getMp_User_Watched().getPlace().getPlaceId();
          	String name = c.getMp_User_Watched().getPlace().getName();
      	    String place_description = c.getMp_User_Watched().getPlace().getDescription();
      	    String create_timestamp = c.getMp_User_Watched().getPlace().getCreate_Timestamp();
      	    String add_timestamp = c.getMp_User_Watched().getPlace().getAdded_Timestamp();
      	    String location_description = c.getMp_User_Watched().getPlace().getDescription();
      	    String location_latitude = c.getMp_User_Watched().getPlace().getLocation().getLatitude();
      	    String location_longitude = c.getMp_User_Watched().getPlace().getLocation().getLongitude();
      	    String website = c.getMp_User_Watched().getPlace().getWebsite();
      	    String place_email = c.getMp_User_Watched().getPlace().getEmail();
      	    
	      	result += "\r\n"+ "place_id: " + place_id
	     			 +"\r\n"+ "name: "+ name
	     			 +"\r\n"+ "description: "+ place_description
	     			 +"\r\n"+ "create_timestamp: "+ create_timestamp
	     			 +"\r\n"+ "add_timestamp: "+ add_timestamp
	     			 +"\r\n"+ " location_description: "+ location_description
	     			 +"\r\n"+ " location_latitude: "+ location_latitude
	     			 +"\r\n"+ " location_longitude: "+ location_longitude
	     			 +"\r\n"+ "website: "+ website
	     			 +"\r\n"+ "email: "+ place_email;
     			 
      	    for(int j=0;j < c.getMp_User_Watched().getPlace().getOpen_Date().getItemCount();j++){
      	    	String open_date = c.getMp_User_Watched().getPlace().getOpen_Date().getItem(j).getDate();
      	    	String open_time = c.getMp_User_Watched().getPlace().getOpen_Date().getItem(j).getOpen_time();
      	    	String close_time = c.getMp_User_Watched().getPlace().getOpen_Date().getItem(j).getClose_time();
      	    	
      	    	result += "\r\n"+ " open_date: "+ open_date
			   			 +"\r\n"+ " open_time: "+ open_time
			   			 +"\r\n"+ " close_time: "+ close_time;
      	    }
      	    String status = c.getMp_User_Watched().getPlace().getStatus();
      	    String exhibition_status = c.getMp_User_Watched().getPlace().getExhibition_Status();
      	    
      	  result += "\r\n"+ "status: "+ status
		   			 +"\r\n"+ "exhibition_status: "+ exhibition_status;
        }

    	textviewDetail.setText(result);
    }
    private void bindWidget(){
    	textviewDetail = (TextView)findViewById(R.id.textviewDetail);
    }
    private void setButtonEventListener(){

    }

}
